<?php

$cat = new tools();
$cat->dbc = $tool->dbc;

	if(empty($_SESSION['CLIENTE_ID'])) $extra1 = "where only_for = 0"; else $extra1 = "where only_for in (0,1) "; 
	$datacat = $cat->estructura_db("select id,nombre,
								   (select count(*) from cont_subcategoria where cat_id = c.id ) as ncat
									from cont_categoria c $extra1 order by orden");


?>


			<ul class="menu-1">
			<li><h2 onclick="location.replace('index.php');">home</h2></li>	
               <?php for($i=0;$i<count($datacat);$i++){ 
			
			if($datacat[$i]['ncat']>0) $link = "SV-listado-categorias-art.php?nivel=1&catid=".$datacat[$i]['id']; else $link = "SV-listado-articulos.php?nivel=1&catid=".$datacat[$i]['id'];
			
			
			 $NIVEL = 1; $CATID = $datacat[$i]['id'];
			
			?>  
                <li> <!--categoria nivel 1-->	
					<h2 onclick="location.replace('<?php echo $link; ?>');"><?php echo utf8_encode($datacat[$i]['nombre']) ?></h2>
					                         
                                  <ul class="menu-2">
                                  
                                  
                                    <?php if($datacat[$i]['ncat']>0){ ///si hay sub 
							
							
									 $query = "select id,nombre,(select count(*) from cont_sub_subcategoria where sub_id = c.id ) as sub,
											   (select count(*) from articulo where cat_nivel = 2 and cat_id = '{$datacat[$i]['id']}' ) as art
											   from cont_subcategoria c where cat_id = '{$datacat[$i]['id']}' order by orden";
											   
									  $cat2 = $cat->estructura_db($query);
									  
									  for($c2=0;$c2<count($cat2);$c2++){ $NIVEL = 2; $CATID = $cat2[$c2]['id']; 
									  
									  
									  if($cat2[$c2]['sub']>0) $link = "SV-listado-categorias-art.php?nivel=$NIVEL&catid=".$CATID; else $link = "SV-listado-articulos.php?nivel=$NIVEL&catid=".$CATID;
									  
									  
									?>
                                  
                                  
                                  
                                      <li><!--categoria nivel 2 (subcategoria)-->
                                          <h3 onclick="location.replace('<?php echo $link; ?>');"><?php echo utf8_encode($cat2[$c2]['nombre']); ?></h3>
                                          
                                          <ul class="menu-3">
                                          
                                          	 <?php if($cat2[$c2]['sub']>0){ ///si hay sub sub
									   
									   				$query = "select id,nombre from cont_sub_subcategoria c where sub_id = '$CATID' order by orden";
											   
									 				 $cat3 = $cat->estructura_db($query);
													 for($c3=0;$c3<count($cat3);$c3++){ $NIVEL = 3; $CATID = $cat3[$c3]['id'];
													 
													  if($cat2[$c2]['sub']>0) $link = "SV-listado-articulos.php?nivel=$NIVEL&catid=".$CATID; else $link = "SV-listado-articulos.php?nivel=$NIVEL&catid=".$CATID;
													 
													 ?>
                                          
                                              <li><!--categoria nivel 3 (ssubcategoria)-->
                                                  <h4 onclick="location.replace('<?php echo $link; ?>');"><?php echo utf8_encode($cat3[$c3]['nombre']); ?></h4>

                                                  		 <?php include('SVG-barra-articulos.php'); ///los articulos 3 ?>
    
                                              </li><!--categoria nivel 3 (ssubcategoria)-->
                                              
                                             <?php }//// categorias nivel 3
									
									
											}else{ include('SVG-barra-articulos.php'); }// ///sino hay sub  sub categorias
											
											?>   
                                           
                                              
                                          </ul>
                                          
                                          
                                      </li><!--categoria nivel 2 (subcategoria)-->
                                      
                                      
                                    <?php }//// categorias nivel 2
									
									
									}else{ include('SVG-barra-articulos.php'); }// ///sino hay sub  sub categorias
									
									?>   
                        
                        
                        
						
					</ul>
				</li> <!--categoria nivel 1-->	
                
              <?php } ////categorias nivel 1?>  
                
			</ul>



